package com.mujin.keji.collectionsystem.module.login.viewmodel;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModel;
import android.content.Context;

import com.mujin.keji.collectionsystem.Constant;
import com.mujin.keji.collectionsystem.base.BaseDto;
import com.mujin.keji.collectionsystem.module.login.dto.LoginDto;
import com.mujin.keji.collectionsystem.module.login.repository.ILoginRepository;
import com.mujin.keji.collectionsystem.module.login.repository.LoginRepository;
import com.mujin.keji.collectionsystem.module.login.views.LoginActivity;
import com.mujin.keji.collectionsystem.module.login.vo.LoginVo;
import com.mujin.keji.collectionsystem.utils.SPUtil;

/**
 * 登录viewmodel
 *
 * @author weishixiong
 * @Time 2018-04-2
 */
public class LoginViewModel extends ViewModel {
    private LiveData<BaseDto<LoginDto>> loginDtoLiveData;
    private BaseDto<LoginDto> loginBaseLiveData;
    private ILoginRepository loginRepository;
    private LoginActivity activity;

    public LiveData<BaseDto<LoginDto>> getLoginDtoLiveData() {
        return loginDtoLiveData;
    }

    public BaseDto<LoginDto> getLoginBaseLiveData() {
        return loginBaseLiveData;
    }

    /**
     * 登录
     *
     * @param username
     * @param password
     */
    public void login(String username, String password, Context context, LoginActivity activity) {
        SPUtil.clearData(Constant.SP.SP);
        loginRepository = new LoginRepository();
        LoginVo vo = new LoginVo();
        vo.setPassword(password);
        SPUtil.putData(Constant.SP.SP, "pwd", password);
        vo.setUsername(username);
//        this.loginDtoLiveData = loginRepository.login(vo,context);

        this.loginBaseLiveData = loginRepository.login(vo, context, activity);


        this.activity = activity;

    }

}
